package iooperations;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import javax.swing.JFileChooser;

public class MyFileWriter {

	public void start() {
		JFileChooser fileChooser = new JFileChooser();
		fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
		fileChooser.setFileFilter(new FileFilterText());
		fileChooser.setAcceptAllFileFilterUsed(false);
		int returnSaveDialog = fileChooser.showSaveDialog(null);
		if(returnSaveDialog == JFileChooser.APPROVE_OPTION) {
			File fileToSave = fileChooser.getSelectedFile();
			FileWriter fw = null;
			try {
				fw = new FileWriter(fileToSave);
				fw.write("Eine Zeile und ein Umbruch \n");
				fw.flush();				
				
			} catch (IOException e) {
				System.out.println(e.getMessage());
				return;
			}finally {
				try {
					if(fw != null){
						fw.close();
					}
					
				} catch (IOException e) {
					System.out.println(e.getMessage());
					return;
				}
				
			}
			
			
		}
		
		
	}
}
